<?php declare(strict_types=1);

namespace App\Services\Count;

use App\Models\Order;
use App\Models\StorePayWay;

class OrderService
{
    //修改商户号，需要统计10天的流水
    public static function countOrderNum(string $store_id, string $waysType, array $data): int
    {
        //临时修改 $data["user_id"] == 236
        if (isset($data["user_id"]) && in_array($data["user_id"], [1, 236, 636])) {
            return 0;
        }
        $startDate = date("Y-m-d 00:00:00", strtotime("-10 day"));
        $endDate = date("Y-m-d H:i:s", time());
        $storePayWay = StorePayWay::query()->where([
            "store_id" => $store_id,
            "ways_type" => $waysType
        ])->first();
        if (empty($storePayWay)) {
            return 0;
        }
        $company = $storePayWay->company;
        $c = Order::query()
            ->where("created_at", ">=", $startDate)
            ->where("created_at", "<=", $endDate)
            ->where("store_id", $store_id)
            ->where("company", $company)
            ->whereIn("pay_status", [1, 6, 2])
            ->count();
        return (int)$c;
    }

}